import { Component, OnInit } from '@angular/core'
import { _HttpClient } from '@delon/theme'
import { ActivatedRoute } from '@angular/router'

import { UserService } from 'app/routes/user/user.service'
import { UserAlinterService } from 'app/routes/user/user-alinter.service'
import { ERoleType } from '@shared/enums'
import { CommonGroupService } from '@shared/services/group.service'
import { IAamsLevel } from '@shared/components/aams-select/aams-select.interface'

@Component({
  selector: 'app-group-detail-tab-userlist',
  templateUrl: './tab-userlist.component.html',
  styleUrls: ['../../../../shared/styles/table.less'],
  providers: [
    { provide: UserService, useClass: UserAlinterService },
  ]
})
export class GroupDetailTabUserlistComponent implements OnInit {
  groupRole = ERoleType.Group
  insCode: string
  params: {[code: string]: string | number}

  constructor(
    public route: ActivatedRoute,
    private commonGroupService: CommonGroupService,
  ) {}

  ngOnInit(): void {
    this.initQueryParams()
    this.initialData()
  }

  initQueryParams(): void {
    this.route.parent.params.subscribe(params => {
      const agentCode = params['id']
      this.params = {
        agentCode,
        userType: IAamsLevel.Group,
      }
    })
  }

  initialData() {
    this.commonGroupService.viewGroup$.value$.subscribe(group => {
      this.insCode = group.insCode
    })
  }
}
